package com.reebake.ideal.security.handler;

import com.reebake.ideal.security.core.AuthenticationFactorConvertor;
import com.reebake.ideal.security.dao.UsernamePasswordAuthenticationToken;
import com.reebake.ideal.security.entity.UsernameAuthenticationFactor;
import org.springframework.security.core.Authentication;

public class UsernameAuthenticationFactorConvertor implements AuthenticationFactorConvertor<UsernameAuthenticationFactor> {

    public Class<UsernameAuthenticationFactor> getFactorType() {
        return UsernameAuthenticationFactor.class;
    }

    public Authentication convert(UsernameAuthenticationFactor authenticationFactor) {
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(authenticationFactor.getCredential());
        authenticationToken.setCaptcha(authenticationFactor.getCaptcha());

        return authenticationToken;
    }
}
